﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GalaSoft.MvvmLight;
using System.Windows.Input;
using GalaSoft.MvvmLight.Command;
using Microsoft.Win32;
using GalaSoft.MvvmLight.Messaging;
using System.Drawing;
using RA.Services;
using RA.UI.Messages;
using RA.UI.Model;

namespace RA.UI.ViewModel
{
    public class ImagesManagerViewModel : ViewModelBase
    {
        #region private
        bool _showContours;
        ImageProcessService _imgProcessService;
        ImagesManagerModel _model;
        #endregion private

        #region CTOrs
        public ImagesManagerViewModel(ImagesManagerModel model)
        {
            _model = model;

            _isMethodSelected = true;
            _showContours = false;
        }
        #endregion CTOrs

        #region Props
        bool _isMethodSelected;
        public bool IsMethodSelected
        {
            get {return _isMethodSelected;}
            set
            {
                if (_isMethodSelected = value)
                { 
                    _isMethodSelected = value;
                    RaisePropertyChanged(() => IsMethodSelected);
                }
            }
        }
        string _selectedPath;
        public string SelectedPath 
        {
            get {return _selectedPath;}

            set
            {
                if(_selectedPath != value)
                {
                    _selectedPath = value;
                    Messenger.Default.Send(new OpenImageMessage(value));
                    RaisePropertyChanged(() => SelectedPath);
                }
            }
        }
        #endregion Props

        #region Commands
        ICommand _openNewImage;
        public ICommand OpenNewImage
        {
            get
            {
                if(_openNewImage == null)
                {
                    _openNewImage = new RelayCommand(() => SelectedPath = _model.OpenFile());
                }

                return _openNewImage;
            }
        }

        ICommand _showContoursCommand;
        public ICommand ShowContoursCommand
        {
            get
            {
                if (_showContoursCommand == null)
                {
                    _showContoursCommand = new RelayCommand<bool>((param) =>
                        {
                            Messenger.Default.Send<ShowContoursMessage>(new ShowContoursMessage(param));
                        }, 

                        (p) => IsMethodSelected
                    );
                }

                return _showContoursCommand;
            }
        }
        #endregion Commands
    }
}
